﻿@using NorthWind.Models
@model List<Order>
@{
    ViewBag.Title = "ViewByClient";
}

@Html.ActionLink("Ajouter une commande", "Create", "Order")
@Html.ActionLink("Toutes les commandes", "AllOrdersSortedByDate", "Order")
@Html.ActionLink("Prochaines commandes", "NextOrders", "Order")
@Html.ActionLink("Vue par client", "ViewByClient", "Order")
@Html.ActionLink("Vue par employee", "ViewByEmployee", "Order")
@Html.ActionLink("Calendrier", "Index", "Calendar")
<br />

<h2>Vue par Client</h2>

<table style="border: none; width: 100%">

    <tr>
        <th>Client</th>
        <th>Numéro</th>
        <th>Employé</th>
        <th>Expéditeur</th>
        <th>Date de Commande</th>
    </tr>



    @{
    
        String customer = "";
        List<Order> listOrderTmp = new List<Order>();

        foreach (Order order in Model)
        {
            if (customer != order.CustomerID)
            {
                bool first = true;
                foreach (Order ord in listOrderTmp)
                {
                    if (first == true)
                    {
                        <tr>
                            <td rowspan="@listOrderTmp.Count">@Html.ActionLink(@order.Customer.CompanyName.ToString(), "Details", "Customer", new { id = order.CustomerID }, null)</td>
                            <td class="center">@ord.OrderID</td>
                            <td>@Html.ActionLink(@ord.Employee.FirstName + " " + @ord.Employee.LastName, "Details", "Employee", new { id = ord.EmployeeID }, null)</td>
                            <td>@Html.ActionLink(@order.Shipper.CompanyName, "Details", "Shipper", new { id = order.ShipVia }, null)</td>
                            <td class="center">@ord.OrderDate.Value.ToShortDateString()</td>
                            <td>@Html.ActionLink("Detail cette commande", "Details", "Order", new { id = ord.OrderID }, null)</td>
                            <td>@Html.ActionImage("Edit", new {id = order.OrderID}, "~/Content/Images/edit.png", "Modifier")</td>
                            <td>@Html.ActionImage("Delete", new {id = order.OrderID}, "~/Content/Images/delete.png", "Supprimer")</td>
                        </tr>
                        first = false;
                    }
                    else
                    {
                    <tr>
                        <td class="center">@ord.OrderID</td>
                        <td>@Html.ActionLink(@ord.Employee.FirstName + " " + @ord.Employee.LastName, "Details", "Employee", new { id = ord.EmployeeID }, null)</td>
                        <td>@Html.ActionLink(@order.Shipper.CompanyName, "Details", "Shipper", new { id = order.ShipVia }, null)</td>
                        <td class="center">@ord.OrderDate.Value.ToShortDateString()</td>
                        <td>@Html.ActionLink("Details", "Details", "Order", new { id = ord.OrderID }, null)</td>
                        <td>@Html.ActionImage("Edit", new {id = order.OrderID}, "~/Content/Images/edit.png", "Modifier")</td>
                        <td>@Html.ActionImage("Delete", new {id = order.OrderID}, "~/Content/Images/delete.png", "Supprimer")</td>
                    </tr>
                    }
                }
                customer = order.CustomerID;
                listOrderTmp.Clear();
                listOrderTmp.Add(order);
            }
            else
            {
                listOrderTmp.Add(order);
            }
        }
    }
</table>
